package com.bj.jiufu.base.interceptor;

import java.io.IOException;

import org.springframework.http.HttpOutputMessage;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;

import com.bj.jiufu.base.RespMsg;
import com.bj.jiufu.util.constant.CryptoConstant;
import com.bj.jiufu.util.crypto.AesUtil;


public class MessageConverterHandler extends MappingJackson2HttpMessageConverter {
	
	protected void writeInternal(Object object, HttpOutputMessage outputMessage) throws IOException 
	{
	    //使用Jackson的ObjectMapper将Java对象转换成Json String
	    
		RespMsg respMsg =(RespMsg)object;
	    
		String json = objectMapper.writeValueAsString(respMsg);
	    //加密
	    String result = AesUtil.encrypt(json, respMsg.getHeader().getUserId()+CryptoConstant.CryPto_primry_Key);
	    //输出
	    outputMessage.getBody().write(result.getBytes());
	}
}
